<template>
  <div>
    <div class="main">
      <eagle-input
        class="input_text"
        label="应急处置卡名称"
        isInputText
        placeholder="请输入"
        v-model="form.Name"
        required
      >
      </eagle-input>
      <eagle-file-upload
        @CallBack="_fileUploadCb"
        :attachs="form.Attachs"
        :maxCount="1"
        :labelName="'文件'"
        :mustInput="true"
        :isMulti="false"
      />
      <div class="btn_submit">
        <eagle-button block type="primary" @click="_submit">
          保存
        </eagle-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      id: this.$route.query.id,
      code: this.$route.query.code,
      filter: {
        id: this.$route.query.id,
      },
      form: {},
    };
  },
  created() {
    if (this.id > 0) {
      this.getDetail();
    } else {
      this.initData();
    }
  },
  methods: {
    _fileUploadCb(attachs) {
      this.form.Attachs = attachs;
    },
    getDetail() {
      let _this = this;
      _this.$axios
      .get("/PlanEmergencyOrgTeamDisposalCard/GetDetail",{params:_this.filter})
      .then((res) => {
        _this.form = res.data;
        _this.form.EmergencyTeamCode = _this.filter.code;
      });
    },
    //初始化实体
    initData() {
      let _this = this;
      _this.$axios
      .get("/PlanEmergencyOrgTeamDisposalCard/InitNewEntity",{params:_this.filter})
      .then((res) => {
        _this.filter.form = res.data;
        _this.filter.form.EmergencyTeamCode = _this.filter.code;
      });
    },
    // 保存
    _submit() {
      if (!this.form.Name) {
        this.$toast("请输入应急处置卡名称");
        return;
      }
      if (!this.form.Attachs) {
        this.$toast("请选择文件");
        return;
      }
      let _this = this;
      _this.$axios
      .post("/PlanEmergencyOrgTeamDisposalCard/PostData",_this.form)
        .then((res) => {
          _this.$toast("保存成功");
          _this.loading = false;
          setTimeout(() => {
           _this.$router.goRefresh();
          }, 500);
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
  },
};
</script>

<style lang="less">
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.block {
  width: 120px;
  height: 120px;
  background-color: #fff;
}
</style>
<style lang="less" scoped>
.space-between {
  justify-content: space-between;
}
</style>
